<?php                                        
require(dirname(__FILE__).'/global.php');   

$submit = $_POST['submit'];
if(!isset($submit)){
    $smarty->assign('img_src','code.php');
    $smarty->display('login.html');
}
else{
    $code = $_POST['code'];
    $userEmail = $_POST['useremail'];
    $userPass = $_POST['userpass'];
    $checkNum = $_SESSION['Checknum'];
    if(empty($code)||empty($userEmail)||empty($userPass)){
        echo '请填完所有项';
    }
    else if($code == $checkNum){
        require(ROOT.'/include/encrypt.class.php');
        $userPass = Encrypt::encrypt($userPass);
        
        $sql = "select UserID,UserName,UserGroup from talking_user where UserEmail='$userEmail' and UserPass='$userPass' and UserGroup = 6";
        $result = $db->query($sql);                                                                 
        if($result || ($result == null)){
            if(count($result)>0){
                $sql = "update talking_user set UserLastLoginTime = '".DateUtil::get_YY_mm_dd_HH_mm_ss()."',UserLastLoginIP = '".$_SERVER['REMOTE_ADDR']."',UserLoginNum = UserLoginNum + 1 where UserEmail='$userEmail'";
                $db->execute($sql);
                
                $_SESSION['user']['id'] = $result[0]['UserID'];
                $_SESSION['user']['name'] = $result[0]['UserName']; 
                $_SESSION['user']['group'] = $result[0]['UserGroup'];
                
                header('Location: index.php');
            }
            else{                                            
                echo '用户名或密码错误';                           
            }
        }
    }                       
    else{                                            
        echo '验证码错误';
    }
}
$db->close();
?>
